<?php

require 'config.php';
class DBB
{
    protected static $DB = NULL;
    
    private function  __construct()
    {
        return NULL;
    }

    /**
     * @return DB
     */
    public static function getInstance()
    {
        if (!self::$DB)
        {
            try
            {
                self::$DB = new PDO(DB_TYPE.':dbname='.DB_NAME.';host='.DB_HOST, DB_USER, DB_PASS);
                self::$DB -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                self::$DB -> beginTransaction();
            }
            catch (PDOException $e)
            {
                echo 'Connection failed: ' . $e->getMessage();
            }
        }
        return self::$DB;
    }

    public function  __clone()
    {
        return NULL;
    }
    
    public function __destruct() 
    {
        self::$DB -> commit();;
    }
}
?>